﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:control="clr-namespace:for7raid.Control"
        xmlns:local="clr-namespace:for7raid.vkPlayer"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
    <DataTemplate x:Key="MediaItemDataTemplate">
        <Grid Tag="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="auto" MinWidth="25"/>
            </Grid.ColumnDefinitions>
            <Grid.Style>
                <Style TargetType="Grid">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsCurrent}" Value="true">
                            <Setter Property="Background" Value="LightGray"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsSelected,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="true">
                            <Setter Property="Background" Value="SlateGray"/>
                        </DataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsCurrent}" Value="true"/>
                                <Condition Binding="{Binding IsSelected,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="true"/>
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter Property="Background" Value="Gray"/>
                                <Setter Property="TextBlock.Foreground" Value="Black"/>
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                    </Style.Triggers>

                </Style>
            </Grid.Style>
            <Grid.ContextMenu>
                <ContextMenu Name="cnxMenu">
                    <MenuItem Header="Поиск по исполнителю" Command="local:PlayerViewModel.SearchByArtistCommand" CommandParameter="{Binding}" InputGestureText="F3">
                        <MenuItem.Icon>
                            <Image Source="../Icons/search.png" Height="24"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Копировать" InputGestureText="Ctrl+C" Name="copy">
                        <MenuItem.Icon>
                            <Image Source="../Icons/clipboard.png" Height="24"/>
                        </MenuItem.Icon>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="PreviewMouseUp">
                                <control:CommandAction Command="local:PlayerViewModel.CopyCommand" CommandParameter="{Binding}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        <MenuItem.Triggers>
                            <EventTrigger RoutedEvent="PreviewMouseUp" >
                                <BeginStoryboard>
                                    <Storyboard>
                                        <BooleanAnimationUsingKeyFrames Storyboard.Target="{Binding RelativeSource={RelativeSource AncestorType=MenuItem}, Path=Parent}" Storyboard.TargetProperty="IsOpen">
                                            <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False"/>
                                        </BooleanAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </MenuItem.Triggers>


                        <MenuItem Command="local:PlayerViewModel.CopyCommand" CommandParameter="{Binding}" InputGestureText="Ctrl+C">
                            <MenuItem.Header>
                                <TextBlock FontWeight="Bold">Копировать название</TextBlock>
                            </MenuItem.Header>
                        </MenuItem>
                        <MenuItem Header="Копировать URL"  Command="local:PlayerViewModel.CopyUrlCommand" CommandParameter="{Binding}" />
                    </MenuItem>

                    <MenuItem  Command="local:PlayerViewModel.EditCommand" CommandParameter="{Binding}" InputGestureText="F2">
                        <MenuItem.Icon>
                            <Image Source="../Icons/document-edit.png" Height="24"/>
                        </MenuItem.Icon>
                        <MenuItem.Resources>
                            <Style TargetType="MenuItem">
                                <Setter Property="Header" Value="Информация..."/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Owner}" Value="{x:Static local:User.MeId}" >
                                        <Setter Property="Header" Value="Редактировать..."/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Resources>
                    </MenuItem>
                    <MenuItem  Command="local:PlayerViewModel.ShowUserInfoCommand" CommandParameter="{Binding}"
                                Header="О владельце" ToolTip="Показывает краткую информацию о владельце записи">
                        <MenuItem.Icon>
                            <Image Source="../Icons/user.png" Height="24"/>
                        </MenuItem.Icon>
                        <MenuItem.Resources>
                            <Style TargetType="MenuItem">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Owner}" Value="{x:Static local:User.MeId}" >
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Resources>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Header="Сообщение другу" ItemsSource="{Binding PlacementTarget.Tag.Friends, RelativeSource={RelativeSource AncestorType=ContextMenu}}" HorizontalContentAlignment="Stretch">
                        <MenuItem.Icon>
                            <Image Source="../Icons/mail.png" Height="24"/>
                        </MenuItem.Icon>


                        <MenuItem.ItemsPanel>
                            <ItemsPanelTemplate>

                                <UniformGrid IsItemsHost="True" Columns="5" />


                            </ItemsPanelTemplate>
                        </MenuItem.ItemsPanel>

                        <MenuItem.ItemTemplate>
                            <DataTemplate>

                                <TextBlock TextDecorations="None" Foreground="Black" HorizontalAlignment="Stretch">
                                    <Hyperlink Command="local:PlayerViewModel.SendMesageCommand" CommandParameter="{Binding}" TextDecorations="None" FontStyle="Normal" FontStretch="Normal" FontWeight="Normal">
                                        <StackPanel>
                                                <Image MaxHeight="60" MaxWidth="60" Source="{Binding Photo, IsAsync=True}"/>
                                                <TextBlock Text="{Binding FirstName}" HorizontalAlignment="Center"
                                                           TextWrapping="WrapWithOverflow"  FontStyle="Normal" TextDecorations="None"  FontStretch="Normal" FontWeight="Normal"/>
                                            <TextBlock Text="{Binding LastName}" HorizontalAlignment="Center"
                                                           TextWrapping="WrapWithOverflow"  FontStyle="Normal" TextDecorations="None" FontStretch="Normal" FontWeight="Normal"/>
                                            </StackPanel>
                                        <!--<TextBlock Text="{Binding FullName}" HorizontalAlignment="Stretch"/>-->
                                    </Hyperlink>
                                    <!--<TextBlock.ToolTip>
                                        <Image MaxHeight="64" MaxWidth="64" Source="{Binding Photo}"/>
                                    </TextBlock.ToolTip>-->
                                </TextBlock>

                            </DataTemplate>
                        </MenuItem.ItemTemplate>
                        <MenuItem.Style>
                            <Style TargetType="MenuItem">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Mode=Self}}" Value="0">
                                        <Setter Property="IsEnabled" Value="False"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Style>
                    </MenuItem>
                    <MenuItem Header="На стену другу" ItemsSource="{Binding PlacementTarget.Tag.Friends, RelativeSource={RelativeSource AncestorType=ContextMenu}}" HorizontalContentAlignment="Stretch">
                        <MenuItem.Icon>
                            <Image Source="../Icons/wall.png" Height="24"/>
                        </MenuItem.Icon>


                        <MenuItem.ItemsPanel>
                            <ItemsPanelTemplate>

                                <UniformGrid IsItemsHost="True" Columns="5" />


                            </ItemsPanelTemplate>
                        </MenuItem.ItemsPanel>

                        <MenuItem.ItemTemplate>
                            <DataTemplate>

                                <TextBlock TextDecorations="None" Foreground="Black" HorizontalAlignment="Stretch">
                                    <Hyperlink Command="local:PlayerViewModel.SendToWallCommand" CommandParameter="{Binding}" TextDecorations="None" FontStyle="Normal" FontStretch="Normal" FontWeight="Normal">
                                        <StackPanel>
                                                <Image MaxHeight="60" MaxWidth="60" Source="{Binding Photo, IsAsync=True}"/>
                                                <TextBlock Text="{Binding FirstName}" HorizontalAlignment="Center"
                                                           TextWrapping="WrapWithOverflow"  FontStyle="Normal" TextDecorations="None"  FontStretch="Normal" FontWeight="Normal"/>
                                            <TextBlock Text="{Binding LastName}" HorizontalAlignment="Center"
                                                           TextWrapping="WrapWithOverflow"  FontStyle="Normal" TextDecorations="None" FontStretch="Normal" FontWeight="Normal"/>
                                            </StackPanel>
                                        <!--<TextBlock Text="{Binding FullName}" HorizontalAlignment="Stretch"/>-->
                                    </Hyperlink>
                                    <!--<TextBlock.ToolTip>
                                        <Image MaxHeight="64" MaxWidth="64" Source="{Binding Photo}"/>
                                    </TextBlock.ToolTip>-->
                                </TextBlock>

                            </DataTemplate>
                        </MenuItem.ItemTemplate>
                        <MenuItem.Style>
                            <Style TargetType="MenuItem">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Mode=Self}}" Value="0">
                                        <Setter Property="IsEnabled" Value="False"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </MenuItem.Style>
                    </MenuItem>
                    
                    <MenuItem Header="На свою стену..." Command="local:PlayerViewModel.SendToWallCommand" CommandParameter="{x:Static local:User.Me}">
                        <MenuItem.Icon>
                            <Image Source="../Icons/home.png" Height="24"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    
                    <Separator/>
                    <MenuItem Header="Добавить в мои записи" Command="local:PlayerViewModel.AddToMeCommand" CommandParameter="{Binding}"
                              InputGestureText="Insert">
                        <MenuItem.Icon>
                            <Image Source="../Icons/button-add.png" Height="24"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Удалить" Command="local:PlayerViewModel.DeleteCommand" CommandParameter="{Binding}"
                              InputGestureText="Shift+Delete">
                        <MenuItem.Icon>
                            <Image Source="../Icons/button-remove.png" Height="24"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Удалить из списка" Command="local:PlayerViewModel.RemoveFromListCommand" CommandParameter="{Binding}"
                              InputGestureText="Delete">
                        <MenuItem.Icon>
                            <Image Source="../Icons/button-remove.png" Height="24"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Header="Скачать..." Command="local:PlayerViewModel.DownloadCommand" CommandParameter="{Binding}" InputGestureText="Ctrl+D">
                        <MenuItem.Icon>
                            <Image Source="../Icons/inbox.png" Height="24"/>
                        </MenuItem.Icon>
                    </MenuItem>

                </ContextMenu>
            </Grid.ContextMenu>
            <CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"  Visibility="Collapsed">
                <CheckBox.Resources>
                    <Style TargetType="CheckBox">
                        <Style.Triggers>
                            <DataTrigger Value="false">
                                <DataTrigger.Binding>
                                    <MultiBinding>
                                        <Binding Path="DataContext.Items" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Window}"/>
                                        <Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType=ListBoxItem}"/>
                                        <MultiBinding.Converter>
                                            <local:SelectedItemsMoreOneConverter/>
                                        </MultiBinding.Converter>
                                    </MultiBinding>


                                </DataTrigger.Binding>
                                <DataTrigger.Setters>
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger.Setters>
                            </DataTrigger>


                        </Style.Triggers>
                    </Style>
                </CheckBox.Resources>
            </CheckBox>
            <ProgressBar Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" Maximum="100" Value="{Binding Path=(local:PlayerViewModel.DownloadProgress)}">
                <ProgressBar.Resources>
                    <Style TargetType="ProgressBar">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=(local:PlayerViewModel.DownloadProgress)}" Value="0">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=(local:PlayerViewModel.DownloadProgress)}" Value="100">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ProgressBar.Resources>
            </ProgressBar>
            <TextBlock Text="{Binding Path=Artist, StringFormat={}{0} - }" FontWeight="Bold" Grid.Column="1"/>
            <TextBlock Text="{Binding Path=Title}" Margin="3,0" Grid.Column="2"/>

            <TextBlock Grid.Column="3" Margin="1,0">
                 <TextBlock.Text>
                    <MultiBinding>
                        <Binding/>
                        <Binding Path="DataContext.QueueList" RelativeSource="{RelativeSource AncestorType=Window}"/>
                        <Binding Path="(local:PlayerViewModel.IsStopAfterThis)"/>
                        <MultiBinding.Converter>
                            <control:ListPositionNoConverter/>
                        </MultiBinding.Converter>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock Grid.Column="4">
                                <TextBlock.Text>
                                 <MultiBinding StringFormat="{}{0:00}:{1:00}">
                                    <Binding Path="Duration.TotalMinutes"/>
                                    <Binding Path="Duration.Seconds"/>
                                </MultiBinding>
                                    </TextBlock.Text>
            </TextBlock>

            <!--Всплывающая подсказка о пользователе-->
            <Popup Placement="Right" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=Grid}}">
                <Popup.IsOpen>
                    <Binding Path="(local:PlayerViewModel.MediaOwner)">
                        <Binding.Converter>
                            <local:NullToFalseConverter/>
                        </Binding.Converter>
                    </Binding>
                </Popup.IsOpen>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseLeave">
                        <local:ClearMediaOwnerAction Media="{Binding}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Border Background="{StaticResource BackgroundBrush}" CornerRadius="3" BorderBrush="Gray">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Image Margin="3" Source="{Binding Path=(local:PlayerViewModel.MediaOwner).Photo}" Grid.RowSpan="3"/>
                        <TextBlock Grid.Column="1" Margin="3" Text="{Binding Path=(local:PlayerViewModel.MediaOwner).FullName}" Foreground="Blue" FontWeight="Bold"/>
                        <TextBlock Grid.Column="1" Grid.Row="1" Margin="3">
                             <Hyperlink Command="local:PlayerViewModel.SearchByFriendCommand" CommandParameter="{Binding Path=(local:PlayerViewModel.MediaOwner)}">
                                <TextBlock Text="Все записи пользователя"/>
                            </Hyperlink>
                        </TextBlock>
                        <TextBlock Grid.Column="1" Margin="3" Grid.Row="2">
                             <Hyperlink Command="local:PlayerViewModel.GoToUserCommand" CommandParameter="{Binding Path=(local:PlayerViewModel.MediaOwner)}">
                                <TextBlock Text="Перейти на страницу пользователя"/>
                            </Hyperlink>
                        </TextBlock>


                    </Grid>
                </Border>

            </Popup>
        </Grid>






    </DataTemplate>
</ResourceDictionary>